package com.cucn.mms.common.service.Interface.Impl;

import com.alibaba.fastjson.JSON;
import com.cucn.mms.common.common.R;
import com.cucn.mms.domain.MediaManageDO;
import com.cucn.mms.common.service.Interface.MediaManageService;
import com.cucn.mms.dao.MediaManageMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author 执念
* @description 针对表【mms_media_info】的数据库操作Service实现
* @createDate 2023-04-24 18:58:50
*/
@Service
@Slf4j
public class MediaManageServiceImpl implements MediaManageService {

    @Autowired
    private MediaManageMapper mediaManageMapper;

    @Override
    public int getTotal() {
        return mediaManageMapper.getTotal();
    }

    @Override
    public Map<String, Object> selectMediaByType(String keyword, String searchType, int offset, int limit) {
        List<MediaManageDO> list = mediaManageMapper.selectMediaByType(keyword,searchType,offset,limit);
        return R.success(list,getTotal());
    }

    @Override
    public Map<String, Object> deleteMediaById(String mediaId) {
        boolean flag = mediaManageMapper.deleteMediaById(mediaId);
        if(flag)
            return R.success();
        return R.error();
    }

    @Override
    public Map<String, Object> updateMedia(Map<String, Object> params) {
        MediaManageDO media = JSON.parseObject(JSON.toJSONString(params), MediaManageDO.class);
        boolean flag = mediaManageMapper.updateMedia(media);
        if(flag)
            return R.success();
        return R.error();
    }

    @Override
    public Map<String, Object> addMedia(String mediaName, Integer mediaCategory, Integer mediaGrade, String mediaUrl) {
        boolean flag = mediaManageMapper.addMedia(mediaName,mediaCategory,mediaGrade,mediaUrl);
        if(flag)
            return R.success();
        return R.error();
    }
}




